#include "random.h"

const int32_t RandomNum::A = 48271;
const int32_t RandomNum::M = 2147483647;
const int32_t RandomNum::Q = RandomNum::M / RandomNum::A;
const int32_t RandomNum::R = RandomNum::M % RandomNum::A;


RandomNum::RandomNum( int32_t seed )
    : m_seed( seed )
{
    if( 0 == m_seed )
        m_seed = time( NULL );
}

int32_t RandomNum::random_i()
{
    int32_t temp_seed = A * ( m_seed % Q ) - R * ( m_seed / Q );
    if( temp_seed >= 0 )
        m_seed = temp_seed;
    else
        m_seed = temp_seed + M;
    return m_seed;
}

double RandomNum::random_f()
{
    return (double)random_i()/(double)M;
}

